package com.example.filedemo.service.impl;

import com.example.filedemo.mapper.FileMapper;
import com.example.filedemo.pojo.UserFile;
import com.example.filedemo.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class FileServiceImpl implements FileService {

    @Autowired
    private FileMapper filemapper;

    @Override
    public List<UserFile> findUserAll() {
        return filemapper.findUserAll();
    }

    @Override
    public void delete(String id) {
        filemapper.delete(id);
    }

    @Override
    public void update(UserFile userFile) {
        filemapper.update(userFile);
    }

    @Override
    public UserFile findById(String id) {
        return filemapper.findById(id);
    }

    @Override
    public void save(UserFile userFile) {
        //userFile.setIsImg()?  //是否是图片 解决方案: 当类型中含有image时说明当前类型一定为图片类型
        String isImg = userFile.getType().startsWith("image") ? "是" : "否";
        userFile.setIsImg(isImg);
        userFile.setDowncounts(0);
        userFile.setUploadTime(new Date());
        filemapper.save(userFile);
    }

}
